package com.ruoyi.project.kbjz.service.impl;

import com.ruoyi.project.kbjz.domain.KbjzCase;
import com.ruoyi.project.kbjz.mapper.KbjzCaseMapper;
import com.ruoyi.project.kbjz.service.IKbjzCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class KbjzCaseServiceImpl implements IKbjzCaseService {
    @Autowired
    private KbjzCaseMapper kbjzCaseMapper;
    @Override
    public String insertCase(KbjzCase kbjzCase) {
        String patientId = kbjzCase.getPatientId().substring(kbjzCase.getPatientId().length()-1);
        //生成病例编号
        String caseId = "CH"+System.currentTimeMillis()+(new Random().nextInt(9000)+1000)+patientId;
        kbjzCase.setCaseId(caseId);
        //指定那个医生创建的病例单
        kbjzCase.setCreateBy(kbjzCase.getDoctorName());
        //创建时间
        kbjzCase.setCreateTime(new Date());
        return kbjzCaseMapper.addCase(kbjzCase) > 0 ? caseId : null;
    }

    @Override
    public List<KbjzCase> selectCaseByPatientId(String patientId) {
        return kbjzCaseMapper.selectCaseByPatientId(patientId);
    }


}
